package com.ruoyi.security.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.security.domain.AfSafetyEducation;
import com.ruoyi.security.service.IAfSafetyEducationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 安全教育Controller
 *
 * @author Felix
 * @date 2021-10-12
 */
@Api(tags = " 安全教育")
@RestController
@RequestMapping("/afSafetyEducation")
public class AfSafetyEducationController extends BaseController {
    @Autowired
    private IAfSafetyEducationService afSafetyEducationService;

    /**
     * 查询安全教育列表
     */
    @ApiOperation(value="查询安全教育列表", notes="查询安全教育列表")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:list")
    @GetMapping("/list")
    public TableDataInfo list(AfSafetyEducation afSafetyEducation) {
        startPage();
        List<AfSafetyEducation> list = afSafetyEducationService.selectAfSafetyEducationList(afSafetyEducation);
        return getDataTable(list);
    }

    /**
     * 导出安全教育列表
     */
    @ApiOperation(value="导出安全教育列表", notes="导出安全教育列表")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:export")
    @Log(title = "安全教育", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfSafetyEducation afSafetyEducation) throws IOException {
        List<AfSafetyEducation> list = afSafetyEducationService.selectAfSafetyEducationList(afSafetyEducation);
        ExcelUtil<AfSafetyEducation> util = new ExcelUtil<AfSafetyEducation>(AfSafetyEducation.class);
        util.exportExcel(response, list, "安全教育数据");
    }
    /**
     * 获取安全教育详细信息
     */
    @ApiOperation(value="获取安全教育详细信息", notes="获取安全教育详细信息")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afSafetyEducationService.selectAfSafetyEducationById(id));
    }

    /**
     * 新增安全教育
     */
    @ApiOperation(value="新增安全教育", notes="新增安全教育")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:add")
    @Log(title = "安全教育", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfSafetyEducation afSafetyEducation) {
        return toAjax(afSafetyEducationService.insertAfSafetyEducation(afSafetyEducation));
    }

    /**
     * 修改安全教育
     */
    @ApiOperation(value="修改安全教育", notes="修改安全教育")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:edit")
    @Log(title = "安全教育", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfSafetyEducation afSafetyEducation) {
        return toAjax(afSafetyEducationService.updateAfSafetyEducation(afSafetyEducation));
    }

    /**
     * 删除安全教育
     */
    @ApiOperation(value="删除安全教育", notes="删除安全教育")
    @ApiImplicitParam(name = "ids", value = "安全教育ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afSafetyEducation:remove")
    @Log(title = "安全教育", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afSafetyEducationService.deleteAfSafetyEducationByIds(ids));
    }
}
